<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // ES6中新增剩余参数，形式为...形参，用于获取多余的参数
        function f1(...nums){
            console.log(nums);
        }
        // f1();
        f1(200,300,400);
        f1(600);

        //剩余参数必须是最后一个参数，否则会报错
        function f2(a,...b){
            console.log(a);
            console.log(b);
        }
        f2(100,200,"cici","lucy",400,50);

        //有了剩余参数(rest),可以求实参的和
        function f3(...c){
            var sum=0;
            for(var i=0;i<c.length;i++){
                sum+=c[i];
            }
            return sum;
        }
        console.log(f3(100,200,300,400,500));
        console.log(f3(89,200,34));
        console.log(f3(1,2,3,4,5,6,5,9));
    </script>
</head>
<body>
    
</body>
</html>